// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dfa.axis.v1_15;

import com.google.api.ads.dfa.lib.client.DfaSession;
import com.google.api.ads.dfa.lib.factory.DfaServices;
import com.google.api.ads.dfa.axis.v1_15.Size;
import com.google.api.ads.dfa.axis.v1_15.SizeRecordSet;
import com.google.api.ads.dfa.axis.v1_15.SizeRemote;
import com.google.api.ads.dfa.axis.v1_15.SizeSearchCriteria;

/**
 * This example gets the size ID for a given width and height.
 *
 * Tags: size.getSize
 *
 * @author Joseph DiLallo
 */
public class GetSize {

  public static void main(String[] args) throws Exception {
    int width = Integer.parseInt("INSERT_WIDTH_HERE");
    int height = Integer.parseInt("INSERT_HEIGHT_HERE");

    // Initialize your session.
    DfaSession session = new DfaSession.Builder().fromFile().build();

    // Request the size service from the service client factory.
    SizeRemote sizeService = new DfaServices().get(session, SizeRemote.class);

    // Get size.
    SizeSearchCriteria sizeSearchCriteria = new SizeSearchCriteria();
    sizeSearchCriteria.setHeight(height);
    sizeSearchCriteria.setWidth(width);
    SizeRecordSet sizeRecordSet = sizeService.getSizes(sizeSearchCriteria);

    // Display size ID.
    if (sizeRecordSet.getRecords().length > 0) {
      for (Size size: sizeRecordSet.getRecords()) {
        System.out.printf("Size ID for \"%sx%s\" is \"%s\".%n", width, height, size.getId());
      }
    } else {
      System.out.println("No sizes found for your criteria.");
    }
  }
}
